// pages/myinfo/myinfo.js
const util = require("../../utils/util.js");
const app = getApp();
const tempUrl = app.globalData.cloudUrl+"myinfo/";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cloudUrl:app.globalData.cloudUrl,
    infoDataJF:{value:0,name:"我的积分"},
    infoDataYE:{value:0,name:"账户余额"},
    infoDataQ:{value:0,name:"优惠券"},
    infoDataK:{value:0,name:"会员卡"},

    funDataSYS:{img:tempUrl+"sys.png",id:"1",name:"扫一扫",showDesc:true},
    funDataQBDD:{img:tempUrl+"dd.png",id:"2",name:"全部订单"},
    funDataWDPJ:{img:tempUrl+"pj.png",id:"3",name:"我的评价"},
    funDataWDYE:{img:tempUrl+"ye.png",id:"4",name:"我的余额"},
    funDataYECZ:{img:tempUrl+"cz.png",id:"5",name:"余额充值"},
    btnName:"注册会员",
    userInfo:{}
  },
  acceptDataFromOpenerPage(e){
    console.log(e)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    //const eventChannel = this.getOpenerEventChannel()
    //eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'});

    util.getAndSetUserInfo(this.onCallBack);
  },
  onCallBack(e){
    const app = getApp();
    const info = app.globalData.userInfo;
    var btnname = "";
    if(info.viplevel > 0){
      btnname = "会员" + info.viplevel;
    }
    else{
      btnname = "注册会员";
    }
    this.setData({userInfo:info,btnName:btnname});
  },
  onTestClick(e){
    util.gotoTestPage();
  },
  onItemClick(e){
    const id = e.currentTarget.dataset.id;
    if(id == "2"){
      util.gotoOrderGoodsPage(0);//
    }
    else if(id == "3"){
      util.gotoCommentMePage();
    }
  },
  onRegisterClick(e){
    if(this.data.userInfo.viplevel <= 0){
      util.gotoMyRegister(e);////
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    wx.setNavigationBarTitle({
      title: '我的',
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})